package info.aquaball.service.userservice;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;

import info.aquaball.data.User;

public class UserServiceImpl implements UserService {

	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	
	@Override
	public void createUser(User user) {
		Entity userEntity = new Entity("Tour");
		userEntity.setProperty("name", user.getName());
		userEntity.setProperty("password", user.getPassword());
		userEntity.setProperty("email", user.getEMail());
		userEntity.setProperty("admin", user.isAdmin());
		
		datastore.put(userEntity);
		user.setId(KeyFactory.keyToString(userEntity.getKey()));		
	}
	
	@Override
	public void deleteUser(String id) {
		datastore.delete(KeyFactory.stringToKey(id));		
	}

}
